<?php
error_reporting ( 0 );
$tit = 'Đăng Nhập';
require_once ("in/tren.php");
echo '<div class="navigation"><b>Đăng Nhập</b></div><div align="right"><div style="border-top: 3px solid #13cfeb;"></div></div></div><div class="main_menu">';
if ($user_id) {
	echo 'Bạn đã đăng nhập!</div>';
} else {
	switch ($_GET ['log']) {
		default :
			echo '<form action="?log=done" method="post">
&bull;Tên Đăng nhập:<br><input type="text" name="nick" value="" size="15"><br>
&bull;Mật khẩu:<br><input type="password" name="password" value="" size="15">
<br><input type="submit" value="Đăng Nhập">
<br>&raquo;<a href="dangki.php">Đăng Kí Tài Khoản</a>!!</form><br></div>';
			break;
		case 'done' :
			$nick = addslashes ( $_POST ['nick'] );
			$password = md5 ( addslashes ( $_POST ['password'] ) );
			$sql_query = @mysql_query ( "SELECT id, nick, password FROM taikhoan WHERE nick='{$nick}'" );
			$taikhoan = @mysql_fetch_array ( $sql_query );
			if (@mysql_num_rows ( $sql_query ) == 0) {
				echo '<img src="../img/loi.png">Tài Khoảng không tồn tại.!<br><a href="?">Quay lại</a></div>';
			} elseif ($password != $taikhoan ['password']) {
				echo '<img src="../img/loi.png">Sai mật khẩu.!<br><a href="?">Quay Lại</a></div>';
			} else {
				@session_start ();
				$_SESSION ['user_id'] = $taikhoan ['id'];
				header ( "Location:index.php" );
			}
			break;
	}
}
require_once ("in/duoi.php");
?>
